<template>
  <div>
    <el-select v-model="value" placeholder="请选择" @change="handleCommissioer">
      <el-option
        v-for="(item, index) in options"
        :key="index"
        :label="item.country"
        :value="item.country"
      >
      </el-option>
    </el-select>
    <el-select
      v-model="secondaryvalue"
      placeholder="请选择"
      @change="handlesecondary"
    >
      <el-option
        v-for="item in secondary"
        :key="item"
        :label="item"
        :value="item"
      >
      </el-option>
    </el-select>
    <div v-if="nextStatus == false" ref="statusOne">
      <div class="animate__animated animate__bounceInDown">
        {{ secondaryvalue }}
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      options: [],
      secondary: [],
      nextStatus: true,
      value: "",
      secondaryvalue: "",
    };
  },
  mounted() {
    let self = this;
    self.getrecentdata();
  },
  methods: {
    getrecentdata() {
      let self = this;
      self
        .$axios({
          methods: "get",
          url: "/api/songjun",
        })
        .then((res) => {
          console.log(res.data);
          self.options = res.data.area;
        });
    },
    handleCommissioer(val) {
      // 二级的联动
      console.log(val);
      let self = this;
      console.log(self.options);
      let data = self.options.filter((item) => {
        return item.country === val;
      });
      console.log(data[0].city);
      self.secondary = data[0].city;
      self.secondaryvalue = "";
      console.log(self.secondary);
    },
    handlesecondary() {
      let self = this;
      if (self.nextStatus == false) {
        self.nextStatus = true;
        self.$nextTick(() => {
          self.nextStatus = false;
        });
      } else {
        self.nextStatus = false;
      }
    },
  },
};
</script>